package com.xm.export.excel.converter;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;

@AllArgsConstructor
@Getter
public class EnumConverter implements Converter{
    private String from;
    private Map<String,String[]> map;
    @Override
    public ConverterType getType() {
        return ConverterType.enums;
    }

    @Override
    public String convert(JSONObject target) {
        String value = target.getString(from);
        for (Map.Entry<String, String[]> entry : map.entrySet()) {
            for (String s : entry.getValue()) {
                if(s.equals(value)){
                    return entry.getKey();
                }
            }
        }
        return value;
    }
}
